﻿#include "stdafx.h"
#include "randommusicclock.h"
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QMediaPlayer>
#include <QSettings>
#include <QMediaPlaylist>
#include <QAudioDeviceInfo>
#include <QAudioOutputSelectorControl>
#include <QMediaService>
#include "mfaudioendpointcontrol_fixed.h"

#ifdef Q_OS_WIN32
#if defined(_MSC_VER) && (_MSC_VER >= 1600)  
# pragma execution_character_set("utf-8")  
#endif 
#endif

#ifdef Q_OS_WIN
char getFreestDisk()
{
	DWORD dwDrivers = GetLogicalDrives();
	ULARGE_INTEGER liMax;
	liMax.QuadPart = 0;
	char cRet = 0;
	for (int i = 0 ; i<26 ; i++)
	{
		if ((dwDrivers & (1<<i))!=0)
		{
			char szDrive[MAX_PATH] = "c:";
			szDrive[0] = 'A' + i;

			if (DRIVE_FIXED == GetDriveTypeA(szDrive))
			{
				ULARGE_INTEGER   uiFreeBytesAvailableToCaller;
				if (GetDiskFreeSpaceExA(szDrive, &uiFreeBytesAvailableToCaller, NULL, NULL))
				{
					if (uiFreeBytesAvailableToCaller.QuadPart > liMax.QuadPart)
					{
						liMax = uiFreeBytesAvailableToCaller;
						cRet = szDrive[0];
					}
				}
			}		
		}
	}
	return cRet;
}
#endif

RandomMusicClock::RandomMusicClock(QWidget *parent)
	: QDialog(parent)
{
	ui.setupUi(this);
	m_bClose = false;
	m_bFirstRun = true;
	m_bOnlyWorkDay = true;
	m_nVolume = 100;
    m_strType = "抖音榜";
	initTrayIcon();
	initCfg();
	initPlayer();
	initAudio();

	QTimer *timer = new QTimer(this);
	connect(timer, &QTimer::timeout, this, &RandomMusicClock::showTime);
	timer->start(1000);

	ui.timeEdit_time->setTime(m_tStartTime);
	ui.checkBox_onlyWorkDay->setChecked(m_bOnlyWorkDay);
	ui.lineEdit_saveDir->setText(m_strSaveDir);
    ui.comboBox_type->setCurrentText(m_strType);

	connect(ui.timeEdit_time, &QDateTimeEdit::timeChanged, this, &RandomMusicClock::timeChanged);
	connect(ui.checkBox_onlyWorkDay, &QCheckBox::stateChanged, this, &RandomMusicClock::onlyWorkdayStateChanged);
	connect(ui.toolButton_vol, &VolumeButton::finishChange, this, &RandomMusicClock::releaseVolumeBotton);
	connect(ui.comboBox_audio, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(audioComboxChanged(const QString &)));

	m_pManager = new QNetworkAccessManager(this);

	m_ScheduleTimer = new QTimer(this);
	m_ScheduleTimer->start(10*1000);
	connect(m_ScheduleTimer, SIGNAL(timeout()), this, SLOT(sltScheduleTimerOut()));

#ifdef Q_OS_WIN
	setAutoRun();
#endif
}

RandomMusicClock::~RandomMusicClock()
{

}

void RandomMusicClock::initTrayIcon()
{
	m_SystemTrayIcon = new QSystemTrayIcon(this);
	QIcon icon = QIcon(":/Resources/logo.png");
	m_SystemTrayIcon->setIcon(icon);
	m_SystemTrayIcon->setToolTip("音乐闹钟");
	connect(m_SystemTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(sltActivatedTrayIcon(QSystemTrayIcon::ActivationReason)));

	createActions();
	createMenu();
	m_SystemTrayIcon->show();
}


void RandomMusicClock::createActions()
{
	m_ShowMainAction = new QAction("显示",this);
	connect(m_ShowMainAction, SIGNAL(triggered()), this, SLOT(sltShowMainAction()));

	m_ExitAppAction = new QAction("退出",this);
	connect(m_ExitAppAction, SIGNAL(triggered()), this, SLOT(sltExitAppAction()));
	return;
}

void RandomMusicClock::createMenu()
{
	m_SysTrayMenu = new QMenu(this);
	m_SysTrayMenu->addAction(m_ShowMainAction);
	m_SysTrayMenu->addSeparator();
	m_SysTrayMenu->addAction(m_ExitAppAction);
	m_SystemTrayIcon->setContextMenu(m_SysTrayMenu);
}

void RandomMusicClock::sltShowMainAction()
{
	show();
	raise();
	activateWindow();
}

void RandomMusicClock::closeEvent(QCloseEvent *e)
{
	if (!m_bClose)
	{
		hide();
		e->ignore();
	}
}

void RandomMusicClock::keyPressEvent(QKeyEvent* e)
{
	qDebug()<<e->key();
	switch (e->key())
	{
	case Qt::Key_Return:
		break;
	case Qt::Key_Enter:
		break;
	case Qt::Key_Escape:
		{
			break;
		}
	default:
		QDialog::keyPressEvent(e);
	}
}


/*
* 当在系统托盘点击菜单内的退出程序操作
*/
void RandomMusicClock::sltExitAppAction()
{
	//if (QMyMessageBox::question(this, "退出该系统，审讯终端将无法进行录像，您确定需要退出吗？") == 1)
	{
		m_bClose = true;
		close();
	}
}

void RandomMusicClock::sltActivatedTrayIcon(QSystemTrayIcon::ActivationReason reason)
{
	switch(reason)
	{
	case QSystemTrayIcon::Trigger:
		//单击托盘图标
		break;
	case QSystemTrayIcon::DoubleClick:
		//双击托盘图标
		//双击后显示主程序窗口
		sltShowMainAction();
		break;
	default:
		break;
	}
}

void RandomMusicClock::audioComboxChanged(const QString& text)
{
	m_strAudio = text;
	saveCfg();
// 	if (m_mediaPlayer.state() != QMediaPlayer::StoppedState)
// 	{
// 		setAudioOutpurDev();
// 	}
}

//设置背景图片  path：图片路径
void RandomMusicClock ::setBackgroundImage(QString path)
{
	QPixmap pixmap = QPixmap(path).scaled(this->size());
	QPalette palette(this->palette());
	palette.setBrush(QPalette::Background, QBrush(pixmap));
	this->setPalette(palette);
}

void RandomMusicClock::releaseVolumeBotton()
{
	m_nVolume = m_mediaPlayer.volume();
	saveCfg();
}

void RandomMusicClock::onlyWorkdayStateChanged(int state)
{
	m_bOnlyWorkDay = (state == Qt::Checked);
	saveCfg();
}

void RandomMusicClock::timeChanged(const QTime & time)
{
	m_tStartTime = time;
	saveCfg();
}

void RandomMusicClock::showTime()
{
	QTime time = QTime::currentTime();
	QString text = time.toString("hh:mm");
	if ((time.second() % 2) == 0)
		text[2] = ' ';
	ui.lcdNumber_time->display(text);
}

void RandomMusicClock::initAudio()
{
	QMap<QString, QString> outputs = MFAudioEndpointControl_Fixed::availableOutputsFriendly();
	for (auto it = outputs.cbegin(), e = outputs.cend(); it != e; ++it)
	{
		ui.comboBox_audio->addItem(it.key(), it.value());
	}

// 	QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
// 	foreach (QAudioDeviceInfo i, devices)
// 		ui.comboBox_audio->addItem(i.deviceName());

	int index = ui.comboBox_audio->findText(m_strAudio);
	if (index != -1)
	{
		ui.comboBox_audio->setCurrentIndex(index);
	}

// 	QMediaService* svc = m_mediaPlayer.service();
// 	if (svc)
// 	{
// 		QAudioOutputSelectorControl* out = qobject_cast<QAudioOutputSelectorControl*>(svc->requestControl(QAudioOutputSelectorControl_iid)); 
// 		if (out)
// 		{
// 			out->setActiveOutput(ui.comboBox_audio->currentText()); 
// 			svc->releaseControl(out);
// 		} 
// 	}
}

void RandomMusicClock::setAudioOutpurDev()
{
	QMediaService* svc = m_mediaPlayer.service();
	if (svc != nullptr)
	{
		QAudioOutputSelectorControl *out = reinterpret_cast<QAudioOutputSelectorControl*>(svc->requestControl(QAudioOutputSelectorControl_iid));
		if (out != nullptr)
		{
			new MFAudioEndpointControl_Fixed_Helper(out); // <- the fix; notice that it's a HELPER class
			out->setActiveOutput(ui.comboBox_audio->currentData().toString()); // we have to pass deviceID, not the name
			svc->releaseControl(out);
		}
	}
}

void RandomMusicClock::initPlayer()
{
/*	ui.toolButton_play->setEnabled(false);*/
	ui.toolButton_play->setToolTip(tr("Play"));
	ui.toolButton_play->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));	
	connect(ui.toolButton_play, &QAbstractButton::clicked, this, &RandomMusicClock::togglePlayback);

	m_mediaPlayer.setVolume(m_nVolume);
	ui.toolButton_vol->setToolTip(tr("Adjust volume"));
	ui.toolButton_vol->setVolume(m_mediaPlayer.volume());
	connect(ui.toolButton_vol, &VolumeButton::volumeChanged, &m_mediaPlayer, &QMediaPlayer::setVolume);

	ui.horizontalSlider_pos->setEnabled(false);
	ui.horizontalSlider_pos->setToolTip(tr("Seek"));	
	connect(ui.horizontalSlider_pos, &QAbstractSlider::valueChanged, this, &RandomMusicClock::setPosition);

	connect(&m_mediaPlayer, &QMediaPlayer::positionChanged, this, &RandomMusicClock::updatePosition);
	connect(&m_mediaPlayer, &QMediaPlayer::durationChanged, this, &RandomMusicClock::updateDuration);
	connect(&m_mediaPlayer, &QMediaObject::metaDataAvailableChanged, this, &RandomMusicClock::updateInfo);
//	connect(&m_mediaPlayer, &QMediaPlayer::error, this, &RandomMusicClock::handleError);
	connect(&m_mediaPlayer, &QMediaPlayer::stateChanged, this, &RandomMusicClock::updateState);
}

void RandomMusicClock::initCfg()
{
	QString file = QCoreApplication::applicationDirPath() + "/RandomMusicClock.cfg";
	QSettings ini(file, QSettings::IniFormat);
	m_strSaveDir = ini.value("/cfg/save_dir").toString();
	m_bOnlyWorkDay = (bool)ini.value("/cfg/only_workday", true).toBool();
	int hour = ini.value("/cfg/start_hour", 13).toInt();
	int min = ini.value("/cfg/start_min", 30).toInt();
	m_nVolume = ini.value("/cfg/volume", 100).toInt();
	m_strAudio = ini.value("/cfg/audio").toString();
    m_strType = ini.value("/cfg/type").toString();
	m_tStartTime = QTime(hour, min);

	if (m_strSaveDir.isEmpty())
	{
#ifdef WIN32
		m_strSaveDir = QString("%1:/RandomMusic").arg(QChar(getFreestDisk()));
#else
		m_strSaveDir = "/home/RandomMusic";
#endif
		saveCfg();
	}
}

void RandomMusicClock::saveCfg()
{
	QString file = QCoreApplication::applicationDirPath() + "/RandomMusicClock.cfg";
	QSettings ini(file, QSettings::IniFormat);
	ini.setValue("/cfg/save_dir", m_strSaveDir);
	ini.setValue("/cfg/only_workday", m_bOnlyWorkDay);
	ini.setValue("/cfg/start_hour", m_tStartTime.hour());
	ini.setValue("/cfg/start_min", m_tStartTime.minute());
	ini.setValue("/cfg/volume", m_nVolume);
	ini.setValue("/cfg/audio", m_strAudio);
    ini.setValue("/cfg/type", m_strType);

}

void RandomMusicClock::on_pushButton_browser_clicked()
{
	QString directory = QFileDialog::getExistingDirectory(this, "请选择保存下载歌曲目录", QDir::currentPath());
	if (!directory.isEmpty())
	{
		ui.lineEdit_saveDir->setText(directory);
		m_strSaveDir = directory;
		saveCfg();
	}
}

void RandomMusicClock::on_pushButton_start_clicked()
{
	//m_strUrl = "http://m10.music.126.net/20210323205705/f3843a2f0dec585ae0df6ca9c0141fad/ymusic/d143/1774/2bfc/885425b2043352aac7f4e3c6dfde0e5c.mp3"
	m_strSaveDir = ui.lineEdit_saveDir->text();
	m_tStartTime = ui.timeEdit_time->time();
	m_bOnlyWorkDay = ui.checkBox_onlyWorkDay->isChecked();
    m_strType = ui.comboBox_type->currentText();
	if (m_strSaveDir.isEmpty())
	{
		QMessageBox::warning(this, "错误", "请输入保存下载歌曲目录");
		return;
	}
	saveCfg();
	getMusic();
// 	m_ScheduleTimer = new QTimer(this);
// 	m_ScheduleTimer->start(30*1000);
// 	connect(m_ScheduleTimer, SIGNAL(timeout()), this, SLOT(sltScheduleTimerOut()));
}

void RandomMusicClock::sltScheduleTimerOut()
{
	if (checkExecute() == false)
	{
		return;
	}
	insertLog("闹钟时间到，开始获取音乐");
	ui.toolButton_play->setEnabled(false);
	getMusic();
}

//https://api.uomg.com/api/rand.music?sort=热歌榜&format=json
bool RandomMusicClock::getMusic()
{
	QNetworkRequest request;
    request.setUrl(QUrl(QString("http://api.uomg.com/api/rand.music?sort=%1&format=json").arg(m_strType)));
	m_getMusicReply = m_pManager->get(request);
	connect(m_getMusicReply, SIGNAL(finished()), this, SLOT(sltHttpFinished())); 
	return true;
}

bool RandomMusicClock::startDownloadFile()
{
	QDir dir;
	dir.mkpath(m_strSaveDir);

	m_strFilePath = m_strSaveDir + "/" + m_strName + ".mp3";

	m_pFile = new QFile(m_strFilePath);
	if (!m_pFile->open(QIODevice::WriteOnly))
	{
		insertLog(QString("创建文件失败 %1").arg(m_strFilePath));
		delete m_pFile;
		m_pFile = NULL;
		return false;
	}

	m_url = QUrl::fromUserInput(m_strUrl);
	QNetworkRequest request;
	request.setUrl(m_url);
	m_downloadReply = m_pManager->get(request);
	connect(m_downloadReply, SIGNAL(finished()), this, SLOT(sltHttpFinished())); 
	connect(m_downloadReply, SIGNAL(readyRead()), this, SLOT(sltHttpReadyRead())); 
	connect(m_downloadReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(sltHttpError(QNetworkReply::NetworkError))); 
	//connect(m_downloadReply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(sltDownloadProgress(qint64, qint64))); 
	return true;
}

void RandomMusicClock::sltFinishRequest(QNetworkReply *reply)
{
	if (reply)
	{
		reply->deleteLater();
	}
}

/*
{
"code": 1,
"data": 
	{
	"name": "隔壁泰山",
	"url": "http:\/\/music.163.com\/song\/media\/outer\/url?id=862101001.mp3",
	"picurl": "http:\/\/p1.music.126.net\/pbT0ag5PXJwYzFJ7YklMCA==\/109951163386629013.jpg"
	}
}
*/
bool RandomMusicClock::parseMusic(const QByteArray& ba)
{
	QJsonParseError jsonError;
	QJsonDocument doucment = QJsonDocument::fromJson(ba, &jsonError);
	if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError) && doucment.isObject()) 
	{ 
		QJsonObject object = doucment.object();
		if (!object.contains("code")) 
		{
			return false;
		}
		int code = object.value("code").toInt();
		if (code != 1)
		{
			insertLog(QString("获取网易云音乐失败，状态码：%1").arg((int)code));
			return false;
		}
		if (!object.contains("data")) 
		{
			insertLog(QString("获取网易云音乐失败，回包：%1").arg(QString::fromUtf8(ba)));
			return false;
		}
		QJsonObject dataObject = object.value("data").toObject();
		if (!dataObject.contains("name")) 
		{
			insertLog(QString("获取网易云音乐失败，回包：%1").arg(QString::fromUtf8(ba)));
			return false;
		}
		m_strName = dataObject.value("name").toString();
		if (!dataObject.contains("url")) 
		{
			insertLog(QString("获取网易云音乐失败，回包：%1").arg(QString::fromUtf8(ba)));
			return false;
		}
		m_strUrl = dataObject.value("url").toString();
		if (m_strUrl.isEmpty() || m_strName.isEmpty())
		{
			insertLog(QString("获取网易云音乐失败，回包：%1").arg(QString::fromUtf8(ba)));
			return false;
		}
		insertLog(QString("获取音乐成功，歌曲：%1").arg(m_strName));
		insertLog(QString("URL: %1").arg(m_strUrl));
		return true;
	}
	return false;
}

void RandomMusicClock::sltHttpFinished()
{
	QNetworkReply* reply = (QNetworkReply*)sender();
	if (reply == m_downloadReply)
	{
		if (m_pFile)
		{
			m_pFile->flush(); 
			m_pFile->close(); 
			delete m_pFile; 
			m_pFile = NULL; 
		}
		const QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
		reply->deleteLater();
		reply = nullptr;

		if (!redirectionTarget.isNull()) 
		{
			const QUrl redirectedUrl = m_url.resolved(redirectionTarget.toUrl());
			QFile file(m_strFilePath);
			if (file.exists())
			{
				file.remove();
			}
			m_strUrl = redirectedUrl.toString();
			startDownloadFile();
			return;
		}
		else
		{
			playUrl(m_strFilePath);
		}
	}
	else if (reply == m_getMusicReply)
	{
		if (reply->error() == QNetworkReply::NoError)
		{
			QByteArray bytes = reply->readAll();
			reply->deleteLater();
			reply = nullptr;
			if (!parseMusic(bytes))
			{
				return;
			}
				insertLog("开始下载歌曲文件");
			if (!startDownloadFile())
			{
				return;
			}

		}
		else
		{
			reply->deleteLater();
			reply = nullptr;
			insertLog(QString("获取音乐信息失败，错误码:%1").arg((int)reply->error()));
			return;
		}
	}
	else
	{
		reply->deleteLater();
		reply = nullptr;
	}

}

void RandomMusicClock::sltHttpReadyRead()
{
	if (m_pFile)
	{
		m_pFile->write(m_downloadReply->readAll());
	}
}

void RandomMusicClock::sltHttpError(QNetworkReply::NetworkError eError)
{
	QString strStatus = QString("下载文件失败，错误码：%1").arg((int)eError);
	insertLog(strStatus);
}

void RandomMusicClock::insertLog(QString text)
{
// 	QString strTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
// 	QString strLog = QString("%1 %2").arg(strTime).arg(text);
// 
// 	QListWidgetItem *item = new QListWidgetItem(ui.listWidget_log);
// 	item->setText(strLog);
// 	ui.listWidget_log->addItem(item);
}

void RandomMusicClock::playUrl(const QUrl &url)
{
	insertLog("播放歌曲");
	ui.toolButton_play->setEnabled(true);
	if (url.isLocalFile()) {
		const QString filePath = url.toLocalFile();
		ui.label_info->setText(QDir::toNativeSeparators(filePath));
		m_strFileName = QFileInfo(filePath).fileName();
	} else {
		ui.label_info->setText(url.toString());
		m_strFileName.clear();
	}
	if (m_mediaPlayer.state() == QMediaPlayer::PlayingState)
		m_mediaPlayer.stop();
	m_mediaPlayer.setMedia(url);
	setAudioOutpurDev();
	m_mediaPlayer.play();
}

bool RandomMusicClock::checkExecute()
{
	if (m_bFirstRun == true)
	{
		m_dtLastRunTime = QDateTime::currentDateTime();
		m_dtLastRunTime = m_dtLastRunTime.addDays(-1);
		m_bFirstRun = false;
	}
	QDateTime dtCurrentTime = QDateTime::currentDateTime();
	if (dtCurrentTime.time().hour() == m_tStartTime.hour() &&
		dtCurrentTime.time().minute() == m_tStartTime.minute())
	{
		qint64 spanSecs = m_dtLastRunTime.secsTo(dtCurrentTime);
		if (spanSecs > 60)
		{
			if (m_bOnlyWorkDay)
			{
				int dayOfWeek = dtCurrentTime.date().dayOfWeek();
				if (dayOfWeek == 6 || dayOfWeek == 7)
				{
					return false;
				}
			}
			m_dtLastRunTime = dtCurrentTime;
			return true;
		}
	}
	m_bFirstRun = false;
	return false;
}

void RandomMusicClock::togglePlayback()
{
// 	if (m_mediaPlayer.mediaStatus() == QMediaPlayer::NoMedia)
// 		GetMusic();
//	else 
	if (m_mediaPlayer.state() == QMediaPlayer::PlayingState)
		m_mediaPlayer.pause();
	else  if (m_mediaPlayer.state() == QMediaPlayer::PausedState)
		m_mediaPlayer.play();
	else
		getMusic();
}

void RandomMusicClock::updateState(QMediaPlayer::State state)
{
	if (state == QMediaPlayer::PlayingState) {
		ui.toolButton_play->setToolTip(tr("Pause"));
		ui.toolButton_play->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
	} else {
		ui.toolButton_play->setToolTip(tr("Play"));
		ui.toolButton_play->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
	}

	if (state == QMediaPlayer::StoppedState)
	{
		insertLog("播放完成");
	}
}

static QString formatTime(qint64 timeMilliSeconds)
{
	qint64 seconds = timeMilliSeconds / 1000;
	const qint64 minutes = seconds / 60;
	seconds -= minutes * 60;
	return QStringLiteral("%1:%2")
		.arg(minutes, 2, 10, QLatin1Char('0'))
		.arg(seconds, 2, 10, QLatin1Char('0'));
}

void RandomMusicClock::updatePosition(qint64 position)
{
	ui.horizontalSlider_pos->setValue(position);
	ui.label_pos->setText(formatTime(position));
}

void RandomMusicClock::updateDuration(qint64 duration)
{
	ui.horizontalSlider_pos->setRange(0, duration);
	ui.horizontalSlider_pos->setEnabled(duration > 0);
	ui.horizontalSlider_pos->setPageStep(duration / 10);
	updateInfo();
}

void RandomMusicClock::setPosition(int position)
{
	// avoid seeking when the slider value change is triggered from updatePosition()
	if (qAbs(m_mediaPlayer.position() - position) > 99)
		m_mediaPlayer.setPosition(position);
}


void RandomMusicClock::updateInfo()
{
	QStringList info;
	if (!m_strName.isEmpty())
		info.append(m_strName);
	if (m_mediaPlayer.isMetaDataAvailable()) {
		QString author = m_mediaPlayer.metaData(QStringLiteral("Author")).toString();
		if (!author.isEmpty())
			info.append(author);
		QString title = m_mediaPlayer.metaData(QStringLiteral("Title")).toString();
		if (!title.isEmpty())
			info.append(title);
	}
	info.append(formatTime(m_mediaPlayer.duration()));
	ui.label_info->setText(info.join(tr(" - ")));
}

void RandomMusicClock::handleError()
{
	ui.timeEdit_time->setEnabled(false);
	const QString errorString = m_mediaPlayer.errorString();
	ui.label_info->setText(errorString.isEmpty()
		? tr("Unknown error #%1").arg(int(m_mediaPlayer.error()))
		: tr("Error: %1").arg(errorString));
}

void RandomMusicClock::on_comboBox_type_currentIndexChanged(const QString &arg1)
{
    m_strType = arg1;
    saveCfg();
}

#ifdef Q_OS_WIN
void RandomMusicClock::setAutoRun()
{
	QSettings nsettings("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",QSettings::NativeFormat);
	QString napppath = QApplication::applicationFilePath();
	QString nappname = QApplication::applicationName();
	napppath = napppath.replace("/","\\");
	nsettings.setValue(nappname,napppath);
}
#endif
